package com.yike.user.controller;

import com.yike.user.param.PlatformMenuParam;
import com.yike.user.service.PlatformMenuService;
import com.yike.user.vo.PlatformMenuTreeVo;
import com.yike.user.vo.PlatformMenuVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.PlatformMenuPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台菜单 控制器
 *
 * @author Sakura
 * @since 2024-10-29
 */
@Slf4j
@RestController
@RequestMapping("/platform/menu")
@Module("user")
@Api(value = "平台菜单API", tags = {"平台菜单"})
public class PlatformMenuController extends BaseController {

    @Autowired
    private PlatformMenuService platformMenuService;

    /**
     * 添加平台菜单
     */
    @PostMapping("/add")
    @OperationLog(name = "添加平台菜单", type = OperationLogType.ADD)
    @ApiOperation(value = "添加平台菜单", response = ApiResult.class)
    public ApiResult<Boolean> addPlatformMenu(@Validated(Add.class) @RequestBody PlatformMenuParam platformMenuParam) throws Exception {
        boolean flag = platformMenuService.savePlatformMenu(platformMenuParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改平台菜单
     */
    @PostMapping("/update")
    @OperationLog(name = "修改平台菜单", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改平台菜单", response = ApiResult.class)
    public ApiResult<Boolean> updatePlatformMenu(@Validated(Update.class) @RequestBody PlatformMenuParam platformMenuParam) throws Exception {
        boolean flag = platformMenuService.updatePlatformMenu(platformMenuParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除平台菜单
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除平台菜单", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除平台菜单", response = ApiResult.class)
    public ApiResult<Boolean> deletePlatformMenu(@PathVariable("id") Long id) throws Exception {
        boolean flag = platformMenuService.deletePlatformMenu(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取平台菜单详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "平台菜单详情", type = OperationLogType.INFO)
    @ApiOperation(value = "平台菜单详情", response = PlatformMenuVo.class)
    public ApiResult<PlatformMenuVo> getPlatformMenu(@PathVariable("id") Long id) throws Exception {
        PlatformMenuVo platformMenu = platformMenuService.getPlatformMenu(id);
        return ApiResult.ok(platformMenu);
    }

    /**
     * 平台菜单分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "平台菜单分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "平台菜单分页列表", response = PlatformMenuVo.class)
    public ApiResult<Paging<PlatformMenuVo>> getPlatformMenuPageList(@Validated @RequestBody PlatformMenuPageParam platformMenuPageParam) throws Exception {
        Paging<PlatformMenuVo> paging = platformMenuService.getPlatformMenuPageList(platformMenuPageParam);
        return ApiResult.ok(paging);
    }

    @GetMapping("/tree")
    //@OperationLog(name = "平台菜单树", type = OperationLogType.PAGE)
    @ApiOperation(value = "菜单树", response = PlatformMenuTreeVo.class)
    public ApiResult<List<PlatformMenuTreeVo>> tree() throws Exception {
        List<PlatformMenuTreeVo> platformMenuTreeVos = platformMenuService.tree();
        return ApiResult.ok(platformMenuTreeVos);
    }

}

